Extract StreamPortal utility from Ressy into PowerKit - #89
Conversation
| public void Jump_SeeksToPortalPosition_Test() | ||
| { | ||
| // Arrange | ||
| var data = new byte[] { 1, 2, 3, 4, 5 }; | ||
| using var stream = new MemoryStream(data); | ||
| var portal = stream.CreatePortal(3); | ||
| stream.Seek(0, SeekOrigin.Begin); | ||
|
|
||
| // Act | ||
| using (portal.Jump()) | ||
| { | ||
| // Assert | ||
| stream.Position.Should().Be(3); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Jump_RestoresPositionOnDispose_Test() |
There was a problem hiding this comment.
Done — merged the two tests into Jump_SeeksToPortalPositionAndRestoresOnDispose_Test in commit Merge Jump_SeeksToPortalPosition and Jump_RestoresPositionOnDispose tests into one. The single test now asserts both that Jump() seeks to the portal position and that Dispose() restores the original position.
There was a problem hiding this comment.
Pull request overview
Ports the StreamPortal concept into PowerKit to provide a reusable utility for saving a stream position and temporarily jumping back to it with automatic restoration via IDisposable.
Changes:
- Added
StreamPortalpublic utility type for capturing a stream position and restoring it after a scoped jump. - Added
Stream.CreatePortal()/Stream.CreatePortal(long)extension methods for convenient portal creation. - Added unit tests validating basic portal creation and jump/restore behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| PowerKit/StreamPortal.cs | Introduces the StreamPortal type with position capture, validation, and Jump() restore semantics. |
| PowerKit/Extensions/StreamExtensions.cs | Adds CreatePortal extension methods to construct StreamPortal instances from a Stream. |
| PowerKit.Tests/StreamPortalTests.cs | Adds tests for portal creation and jump/restore behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## prime #89 +/- ##
==========================================
+ Coverage 86.35% 86.43% +0.08%
==========================================
Files 74 75 +1
Lines 1253 1268 +15
Branches 234 235 +1
==========================================
+ Hits 1082 1096 +14
Misses 121 121
- Partials 50 51 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Ports
StreamPortalfrom Ressy into PowerKit as a first-class public utility.Changes
StreamPortal.cs— new public class that captures a stream position and exposesJump(), which seeks to that position and returns anIDisposablethat restores the original position on dispose. Constructor guards against non-seekable streams and negative positions.StreamExtensions.cs— two newCreatePortalextension methods onStream: one targeting the current position, one accepting an explicit offset.Usage